﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Telerik.Web.UI;
using KPIS.GERP.GFMS.IBLL;
using KPIS.GERP.GFMS.BLL;
using KPIS.GERP.GFMS.MODEL;
using KPIS.GERP.GFMS.APP.App_UI.Commons;

namespace KPIS.GERP.GFMS.APP.App_UI.Forms
{
    public partial class FIM_ExpenseRateEmps : System.Web.UI.Page
    {
        //Main main = new Main();
        //IBLL_FIM_MAS_ExpenseRates ExpRate = new B_FIM_MAS_ExpenseRates();
        //IBLL_FIM_MAS_ExpenseRateTypes ExpRateType = new B_FIM_MAS_ExpenseRateTypes();
        //IBLL_FIM_MAS_ExpenseRateTypeGroups ExpRateTypeGrp = new B_FIM_MAS_ExpenseRateTypeGroups();

        //protected void Page_Load(object sender, EventArgs e)
        //{
        //    if (!IsPostBack)
        //    {
        //        string strBgmSourceSeq = Request.QueryString["BgmSourceSeq"];
        //        txtBgmExpSeq.Text = Request.QueryString["Seq"];
        //        txtBgmSourceSeq.Text = strBgmSourceSeq;
        //        SetQty(txtBgmExpSeq.Text);
        //        LoadTravelers();
        //        cmdOK.OnClientClick = string.Format("returnToParent('{0}', '{1}', '{2}', '{3}', '{4}')", txtSumBathAmount.ClientID
        //            , Request.QueryString["txtAmount"], Request.QueryString["txtExchangeRate"], Request.QueryString["txtBathAmount"], Request.QueryString["txGrpAmount"]);
        //    }

        //    SetSummary();
        //}

        //protected void SetSummary()
        //{
        //    double dExpRateAmount = 0;
        //    double dDay = 0;
        //    double dHour = 0;
        //    double dMinute = 0;
        //    double dAmount = 0;
        //    double dSumBathAmount = 0;

        //    for (int i = 0; i < grdFimExpenseRate.Items.Count; i++)
        //    {
        //        GridDataItem dataItem = grdFimExpenseRate.Items[i];
        //        RadNumericTextBox txtExpRateAmount = (RadNumericTextBox)dataItem["quantity"].FindControl("txtExpRateAmount");
        //        RadNumericTextBox txtDay = (RadNumericTextBox)dataItem["quantity"].FindControl("txtDay");
        //        RadNumericTextBox txtHour = (RadNumericTextBox)dataItem["quantity"].FindControl("txtHour");
        //        RadNumericTextBox txtMinute = (RadNumericTextBox)dataItem["quantity"].FindControl("txtMinute");
        //        RadNumericTextBox txtAmount = (RadNumericTextBox)dataItem["amount"].FindControl("txtAmount");

        //        if (txtExpRateAmount.Text.Length > 0)
        //            dExpRateAmount = Convert.ToDouble(txtExpRateAmount.Text);
        //        else
        //            dAmount = 0;

        //        if (txtDay.Text.Trim().Length > 0)
        //            dDay = Convert.ToDouble(txtDay.Text);
        //        else
        //            dDay = 1;

        //        if (txtHour.Text.Trim().Length > 0)
        //            dHour = Convert.ToDouble(txtHour.Text);
        //        else
        //            dHour = 1;

        //        if (txtMinute.Text.Trim().Length > 0)
        //            dMinute = Convert.ToDouble(txtMinute.Text);
        //        else
        //            dMinute = 1;

        //        dAmount = dExpRateAmount * dDay * dHour * dMinute;
        //        txtAmount.Text = dAmount.ToString();
        //        dSumBathAmount += dAmount;
        //    }

        //    txtSumBathAmount.Value = dSumBathAmount;
        //}

        //protected void LoadTravelers()
        //{
        //    DataTable dtb = (DataTable)Session["M_FIM_MoneyRequestTravelers"];
        //    grdFimExpenseRate.DataSource = dtb;
        //    grdFimExpenseRate.DataBind();
        //}

        //protected void SetQty(string strBgmExpSeq)
        //{
        //    ViewState["bRelate"] = ExpRateType.GetRelate(strBgmExpSeq);
        //}

        //protected void grdFimExpenseRate_ItemDataBound(object sender, GridItemEventArgs e)
        //{
        //    if (e.Item is GridDataItem)
        //    {
        //        GridDataItem dataItem = (GridDataItem)e.Item;
        //        RadComboBox ddlExpRateSeq = (RadComboBox)dataItem["emp_rate_seq"].FindControl("ddlExpRateSeq");
        //        HtmlInputHidden txtAmountMin = (HtmlInputHidden)dataItem["quantity"].FindControl("hAmountMin");
        //        HtmlInputHidden txtAmountMax = (HtmlInputHidden)dataItem["quantity"].FindControl("hAmountMax");
        //        RadNumericTextBox txtExpRateAmount = (RadNumericTextBox)dataItem["quantity"].FindControl("txtExpRateAmount");
        //        RadNumericTextBox txtDay = (RadNumericTextBox)dataItem["quantity"].FindControl("txtDay");
        //        RadNumericTextBox txtHour = (RadNumericTextBox)dataItem["quantity"].FindControl("txtHour");
        //        RadNumericTextBox txtMinute = (RadNumericTextBox)dataItem["quantity"].FindControl("txtMinute");
        //        Label lblDay = (Label)dataItem["quantity"].FindControl("lblDay");
        //        Label lblHour = (Label)dataItem["quantity"].FindControl("lblHour");
        //        Label lblMinute = (Label)dataItem["quantity"].FindControl("lblMinute");
        //        RadNumericTextBox txtAmount = (RadNumericTextBox)dataItem["amount"].FindControl("txtAmount");
        //        string strOldClassSeq = main.WebString(dataItem["old_class_seq"].Text);
        //        string strClassSeq = main.WebString(dataItem["class_seq"].Text);
        //        bool[] bRelate = (bool[])ViewState["bRelate"];

        //        if (strClassSeq.Length == 0)
        //        {
        //            strClassSeq = strOldClassSeq;
        //        }

        //        ddlExpRateSeq.DataSource = ExpRateType.GetClassExpRateList(strClassSeq, txtBgmSourceSeq.Text, txtBgmExpSeq.Text);
        //        ddlExpRateSeq.DataBind();
        //        txtDay.Text = (Session["strDayCount"] != null ? Session["strDayCount"].ToString() : "1");
        //        txtHour.Text = "1";
        //        txtMinute.Text = "1";
        //        ddlExpRateSeq.SelectedIndex = 0;
        //        UpdateExpRateAmount(ddlExpRateSeq.SelectedValue, dataItem);

        //        txtExpRateAmount.Attributes.Add("OnBlur", string.Format("txtBlur('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}')"
        //            , txtExpRateAmount.ClientID, txtDay.ClientID
        //            , txtHour.ClientID, txtMinute.ClientID, txtAmount.ClientID
        //            , txtAmountMin.ClientID, txtAmountMax.ClientID));
        //        txtExpRateAmount.Attributes.Add("OnFocus", string.Format("txtFocus('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}')"
        //            , txtExpRateAmount.ClientID, txtDay.ClientID
        //            , txtHour.ClientID, txtMinute.ClientID, txtAmount.ClientID
        //            , txtAmountMin.ClientID, txtAmountMax.ClientID));

        //        if (bRelate[0])
        //        {
        //        }

        //        if (bRelate[1])
        //        {
        //            txtDay.Attributes.Add("OnBlur", string.Format("txtBlur('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}')"
        //                , txtExpRateAmount.ClientID, txtDay.ClientID
        //                , txtHour.ClientID, txtMinute.ClientID, txtAmount.ClientID
        //                , txtAmountMin.ClientID, txtAmountMax.ClientID));
        //            txtDay.Attributes.Add("OnFocus", string.Format("txtFocus('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}')"
        //                , txtExpRateAmount.ClientID, txtDay.ClientID
        //                , txtHour.ClientID, txtMinute.ClientID, txtAmount.ClientID
        //                , txtAmountMin.ClientID, txtAmountMax.ClientID));
        //            txtDay.Visible = true;
        //            lblDay.Visible = true;
        //        }

        //        if (bRelate[2])
        //        {
        //            txtHour.Attributes.Add("OnBlur", string.Format("txtBlur('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}')"
        //                , txtExpRateAmount.ClientID, txtDay.ClientID
        //                , txtHour.ClientID, txtMinute.ClientID, txtAmount.ClientID
        //                , txtAmountMin.ClientID, txtAmountMax.ClientID));
        //            txtHour.Attributes.Add("OnFocus", string.Format("txtFocus('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}')"
        //                , txtExpRateAmount.ClientID, txtDay.ClientID
        //                , txtHour.ClientID, txtMinute.ClientID, txtAmount.ClientID
        //                , txtAmountMin.ClientID, txtAmountMax.ClientID));
        //            txtHour.Visible = true;
        //            lblHour.Visible = true;
        //        }

        //        if (bRelate[3])
        //        {
        //            txtMinute.Attributes.Add("OnBlur", string.Format("txtBlur('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}')"
        //                , txtExpRateAmount.ClientID, txtDay.ClientID
        //                , txtHour.ClientID, txtMinute.ClientID, txtAmount.ClientID
        //                , txtAmountMin.ClientID, txtAmountMax.ClientID));
        //            txtMinute.Attributes.Add("OnFocus", string.Format("txtFocus('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}')"
        //                , txtExpRateAmount.ClientID, txtDay.ClientID
        //                , txtHour.ClientID, txtMinute.ClientID, txtAmount.ClientID
        //                , txtAmountMin.ClientID, txtAmountMax.ClientID));
        //            txtMinute.Visible = true;
        //            lblMinute.Visible = true;
        //        }
        //    }
        //}

        //protected void ddlExpRateSeq_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        //{
        //    UpdateExpRateAmount(e.Value, (GridDataItem)((RadComboBox)o).Parent.Parent);
        //}

        //private void UpdateExpRateAmount(string strExpRateSeq, GridDataItem dataItem)
        //{
        //    M_FIM_MAS_ExpenseRates info = ExpRate.GetInfo(strExpRateSeq);
        //    HtmlInputHidden txtAmountMin = (HtmlInputHidden)dataItem["quantity"].FindControl("hAmountMin");
        //    HtmlInputHidden txtAmountMax = (HtmlInputHidden)dataItem["quantity"].FindControl("hAmountMax");
        //    RadNumericTextBox txtExpRateAmount = (RadNumericTextBox)dataItem["quantity"].FindControl("txtExpRateAmount");
        //    RadNumericTextBox txtDay = (RadNumericTextBox)dataItem["quantity"].FindControl("txtDay");
        //    RadNumericTextBox txtHour = (RadNumericTextBox)dataItem["quantity"].FindControl("txtHour");
        //    RadNumericTextBox txtMinute = (RadNumericTextBox)dataItem["quantity"].FindControl("txtMinute");
        //    RadNumericTextBox txtAmount = (RadNumericTextBox)dataItem["amount"].FindControl("txtAmount");

        //    double dAmountMin = (info.amount_min != null ? info.amount_min.Value : 0);
        //    double dAmountMax = (info.amount_max != null ? info.amount_max.Value : 0);
        //    double dDay = (txtDay.Text.Trim().Length > 0 ? txtDay.Value.Value : 0);
        //    double dHour = (txtHour.Text.Trim().Length > 0 ? txtHour.Value.Value : 0);
        //    double dMinute = (txtMinute.Text.Trim().Length > 0 ? txtHour.Value.Value : 0);

        //    txtAmountMin.Value = dAmountMin.ToString();
        //    txtAmountMax.Value = dAmountMax.ToString();
        //    txtExpRateAmount.Text = dAmountMax.ToString("#,###.##");
        //    txtAmount.Text = (dAmountMax * dDay * dHour * dMinute).ToString("#,###.##");
        //}
    }
}
